package org.mvn_spring_jsf_jar.util;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;

public class PrintExample {

	public static void main(String[] args) {
		// DocFlavor flavor = DocFlavor.STRING.TEXT_PLAIN;
		// PrintService service =
		// PrintServiceLookup.lookupDefaultPrintService();
		// DocPrintJob pj = service.createPrintJob();
		// byte[] bytes = "fijate si imprime".getBytes();
		// Doc doc = (Doc) new SimpleDoc("hola",flavor,null);
		// try {
		// pj.print(doc, null);
		// } catch (Exception e) {
		// }

		// DocFlavor docFlavor = DocFlavor.STRING.TEXT_PLAIN;
		// System.out.println("DocFlavor Mime-Type: " + docFlavor.toString());
		// PrintRequestAttributeSet printAttributes = new
		// HashPrintRequestAttributeSet();
		// printAttributes.add(MediaSizeName.ISO_A4);
		// DocAttributeSet attributes = new HashDocAttributeSet();
		// attributes.add(MediaSizeName.ISO_A4);
		//
		// // get the default printer
		// PrintService printService = PrintServiceLookup
		// .lookupDefaultPrintService();
		// System.out.println("Printer found: " + printService.getName());
		// DocFlavor[] flavors = printService.getSupportedDocFlavors();
		// for (DocFlavor flavor : flavors) {
		// LOG.info(flavor.toString());
		// }

		// StringReader sr = new StringReader(incidentFormString.toString());

		// DocPrintJob job = printService.createPrintJob();
		// Doc doc = new SimpleDoc("impresion", docFlavor, attributes);
		//
		// job.addPrintJobListener(new PrintJobListener() {
		// public void printDataTransferCompleted(PrintJobEvent printJobEvent) {
		// System.out.println("printDataTransferCompleted");
		// }
		//
		// public void printJobCompleted(PrintJobEvent printJobEvent) {
		// System.out.println("printJobCompleted");
		// }
		//
		// public void printJobFailed(PrintJobEvent printJobEvent) {
		// System.out.println("printJobFailed");
		// }
		//
		// public void printJobCanceled(PrintJobEvent printJobEvent) {
		// System.out.println("printJobCanceled");
		// }
		//
		// public void printJobNoMoreEvents(PrintJobEvent printJobEvent) {
		// System.out.println("printJobNoMoreEvents");
		// }
		//
		// public void printJobRequiresAttention(PrintJobEvent printJobEvent) {
		// System.out.println("printJobRequiresAttention");
		// }
		// });
		//
		// try {
		// job.print(doc, printAttributes);
		// } catch (PrintException e) {
		// // TODO Auto-generated catch block
		// System.out.println("error al imprimir: " + e);
		// }

		char[] printdata = "hello world\n".toCharArray();
		DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
		PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
		DocPrintJob pjob = pservice.createPrintJob();
		Doc doc = new SimpleDoc(printdata, flavor, null);
		try {
			pjob.print(doc, null);
		} catch (PrintException e) {
			// TODO Auto-generated catch block
			System.out.println("error al imprimir: " + e);
		}

	}
}
